﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// CompanyDAO 的摘要说明
/// </summary>
public class CompanyDAO
{
    SqlHelp help = new SqlHelp();
	public CompanyDAO()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public DataTable GetCompany()
    {
        return help.GetDataTable("select CoCode, CoName, CoTel, CoFax, CoAddress, CoDesc, DeleteFlag, AddAuthor, AddDate, UpdateAuthor, UpdateDate from B_Company  where DeleteFlag<>1 ");
    }

    public int AddCompany(CompanyModel model)
    {
        string sql = "insert into B_Company(CoCode, CoName, CoTel, CoFax, CoAddress, CoDesc, DeleteFlag, AddAuthor, AddDate, UpdateAuthor, UpdateDate) "
            + " values(@CoCode, @CoName, @CoTel, @CoFax, @CoAddress, @CoDesc, @DeleteFlag, @AddAuthor, @AddDate, @UpdateAuthor, @UpdateDate)";
        SqlParameter[] paras = new SqlParameter[]{
            new SqlParameter("@CoCode",model.CoCode),
            new SqlParameter("@CoName",model.CoName),
            new SqlParameter("@CoTel",model.CoTel),
            new SqlParameter("@CoFax",model.CoFax),
            new SqlParameter("@CoAddress",model.CoAddress),
            new SqlParameter("@CoDesc",model.CoDesc),
            new SqlParameter("@DeleteFlag","0"),
            new SqlParameter("@AddAuthor",model.UserCode),
            new SqlParameter("@AddDate",model.date),
            new SqlParameter("@UpdateAuthor",model.UserCode),
            new SqlParameter("@UpdateDate",model.date)};

        return help.RunSqlInt(sql, paras);
    }

    public int EditCompany(CompanyModel model)
    {
        string sql = " update B_Company set CoName=@CoName, CoTel=@CoTel, CoFax=@CoFax, CoAddress=@CoAddress, CoDesc=@CoDesc, UpdateAuthor=@UpdateAuthor, UpdateDate=@UpdateDate"
            + "  where CoCode=@CoCode ";
        SqlParameter[] paras = new SqlParameter[]{
            new SqlParameter("@CoCode",model.CoCode),
            new SqlParameter("@CoName",model.CoName),
            new SqlParameter("@CoTel",model.CoTel),
            new SqlParameter("@CoFax",model.CoFax),
            new SqlParameter("@CoAddress",model.CoAddress),
            new SqlParameter("@CoDesc",model.CoDesc),
            new SqlParameter("@UpdateAuthor",model.UserCode),
            new SqlParameter("@UpdateDate",model.date)};

        return help.RunSqlInt(sql, paras);
    }

    public int DeleteCompany(string coCode)
    {
        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@CoCode", coCode) };
        return help.RunProcInt("DeleteCompany", paras);
    }
}
